<script>
    <?php use yii\helpers\Url;$this->beginBlock('js_resource') ?>
    //导入数据
    $(document).on('click', '.daoru', function () {
        layer.open({
            type: 1,
            title: "资源导入",
            area: ["350px", "200px"],
            content: $('#open'),
        });
    });
    //上传
    $(document).on('change', '#file', function () {
        console.log('上传');
        var excel_file = $(this);
        var fd = new FormData();
        fd.append('excel', excel_file[0].files[0]);

        var up = layer.msg('上传中', {
            icon: 16
            , shade: 0.01
        });
        $.ajax({
            url: '<?=Url::toRoute('upload-file')?>',//'/resource/resource/upload-file'
            type: 'POST',
            data: fd,
            processData: false,
            contentType: false,
            dataType: "json",
            success: function (msg) {

                if (msg.status == 200) {
                    layer.msg(msg['msg'], {icon: 1, time: 1000}, function () {
                        $('#file_value').val(msg['data']);
                    });
                } else {
                    layer.msg(msg['msg'], {icon: 2, time: 1000});
                }
            },
            error: function () {
            },
            complete: function () {
                layer.close(up);
            }
        })
    });
    //开始导入
    $(document).on('click', '#start_daoru', function () {
        var file = $('#file_value').val();
        if (!file) {
            layer.msg('没有导入数据', {icon: 2});
            return false;
        }
        $.ajax({
            type: "POST",
            url: '<?=Url::toRoute('import-excel333')?>',
            data: {
                file: file,
                r_type:r_type,
            },
            dataType: 'json'
        })
            .done(function (msg) {
                console.log(msg);
                if (msg['status'] == 200) {
                    layer.msg(msg['msg'], {icon: 1, time: 1000}, function () {
                        $.pjax.reload({container: "#centerView"});
                        layer.closeAll();
                    });
                } else {
                    layer.msg(msg['msg'], {icon: 2});
                }
            });
    });

    //获取复选框id
    function allChecked() {

        var id = [];
        var dom = $('.grid-view tbody').find('input[type=checkbox]:checked');
        if (dom.length) {
            $.each(dom, function () {
                id.push($(this).val())
            });
        } else {
            return 0;
        }
        return id;
    }
    <?php $this->endBlock() ?>
</script>
<?php $this->registerJs($this->blocks['js_resource'], \yii\web\View::POS_END); ?>